# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Bert Peters <bert@bertptrs.nl>

pkgname=ruby-kramdown-parser-gfm
_pkgname="${pkgname#ruby-}"
pkgver=1.1.0
pkgrel=2
pkgdesc='A kramdown parser that converts GitHub Flavoured Markdown to HTML'
arch=('any')
url='https://github.com/kramdown/parser-gfm'
license=('MIT')
depends=('ruby' 'ruby-kramdown')
makedepends=('git' 'ruby-rdoc' 'ruby-rake')
options=('!emptydirs')
_commit='bb3a2b2572b3b5a290465c0d6976f0e02628b207'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  # unable to build from git tag
  grep VERSION lib/kramdown/parser/gfm_version.rb | sed -e "s/\s*GFM_VERSION = '\(.*\)'/\1/"
}

build() {
  cd "$pkgname"

  rake gem
}

package() {
  cd "$pkgname"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "pkg/$_pkgname-$pkgver.gem"

  # delete cache
  rm -rf "$pkgdir/$_gemdir/cache"

  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname" 
  ln -sf "$_gemdir/gems/$_pkgname-$pkgver/COPYING" "$pkgdir/usr/share/licenses/$pkgname"
}
